
window.top.Historics.Utils = {
  hasClassName: function(element, className) {
    var elementClassName = element.className;
    return (elementClassName.length > 0 && (elementClassName == className ||
      new RegExp("(^|\\s)" + className + "(\\s|$)").test(elementClassName)));
  },

  addClassName: function(element, className) {
    if (!window.top.Historics.Utils.hasClassName(element, className))
      element.className += (element.className ? ' ' : '') + className;
    return element;
  },

  removeClassName: function(element, className) {
    element.className = element.className.replace(
      new RegExp("(^|\\s+)" + className + "(\\s+|$)"), ' ');
    element.className = window.top.Historics.Utils.strip(element.className);
    return element;
  },
  strip: function(str) {
    return str.replace(/^\s+/, '').replace(/\s+$/, '');
  },
  truncate: function(str, length, truncation){
  	length = length || 30;
    truncation = truncation === undefined ? '...' : truncation;
    return str.length > length ?
      str.slice(0, length - truncation.length) + truncation : String(str);
  }
}